package com.zhongen.wflow.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhongen.admin.api.entity.SysUser;
import com.zhongen.wflow.bean.entity.WflowUsers;
import com.zhongen.wflow.bean.vo.OrgTreeVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author : willian fu
 * @date : 2022/6/27
 */
public interface WflowUsersMapper extends BaseMapper<SysUser> {

	/**
	 * 查询该部门下的所有用户
	 * @param deptId 部门ID
	 * @return 用户列表 type为固定值user
	 */
	@Select("SELECT ou.user_id id, ou.name , 'user' AS 'type', ou.avatar "
			+ "FROM sys_user_dept oud LEFT JOIN sys_user ou ON ou.user_id = oud.user_id "
			+ "WHERE oud.dept_id = #{deptId}")
	List<OrgTreeVo> selectUsersByDept(@Param("deptId") String deptId);

	/**
	 * 通过拼音搜索用户，全拼和拼音首字母模糊搜索
	 * @param py 拼音
	 * @return 搜索的用户列表 type为固定值user
	 */
	@Select("SELECT ou.user_id id, ou.name, 'user' AS 'type', ou.avatar FROM sys_user ou "
			+ "WHERE ou.name LIKE '%${py}%' OR pingyin LIKE '%${py}%' OR py LIKE '%${py}%'")
	List<OrgTreeVo> selectUsersByPy(@Param("py") String py);

	/**
	 * 通过id获取用户姓名
	 * @param userId id
	 * @return 搜索的用户列表 type为固定值user
	 */
	@Select("SELECT ou.name FROM sys_user ou "
			+ "WHERE ou.user_id = #{userId} ")
	String selectNameByUserId(@Param("userId") String userId);

}
